package cn.com.ddapp.ddm.ui.order;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.hdos.usbdevice.publicSecurityIDCardLib;
import com.zhy.autolayout.utils.AutoUtils;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.UrgentDayAdpter;
import cn.com.ddapp.ddm.adapter.UrgentTimeAdpter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.ActivityManager;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.Entity;
import cn.com.ddapp.ddm.bean.mine.UserData;
import cn.com.ddapp.ddm.bean.order.Coupon;
import cn.com.ddapp.ddm.bean.settleShopcar.Accept;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleAccountsEntity;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleGoods;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleShopGoodsCar;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.AtOneBuyActivity;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.ui.mine.AddAddressActivity;
import cn.com.ddapp.ddm.ui.mine.AddressActivity;
import cn.com.ddapp.ddm.util.MD5;
import cn.com.ddapp.ddm.util.NetUtils;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.StringUtils;
import cn.com.ddapp.ddm.util.TDevice;
import cn.com.ddapp.ddm.util.TLog;
import cn.com.ddapp.ddm.widget.TipsToast;
import okhttp3.Call;

/**
 * Created by caopenghui on 2016-08-02.
 */
public class OrderSureActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.title)
    TextView title;

    @BindView(R.id.action)
    TextView action;

    @BindView(R.id.back)
    ImageView back;

    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.accepter)
    TextView accepterTextView;
    @BindView(R.id.tel)
    TextView telTextView;
    @BindView(R.id.address)
    TextView addressTextView;
    @BindView(R.id.commit_order)
    TextView mCommitOrder;
    @BindView(R.id.error_layout)
    EmptyLayout mEmptyLayout;

    @BindView(R.id.accpetNone)
    RelativeLayout mAccpetNone;
    @BindView(R.id.acceptLinearlayout)
    LinearLayout mAcceptLinearlayout;

    @BindView(R.id.buyerTipsEditText)
    EditText mBuyerTips;//买家留言
    @BindView(R.id.total_account)
    TextView mTotalMoney;//订单合计

    @BindView(R.id.vipTextView)
    TextView vipTextView;
    @BindView(R.id.vipMoneyAmount)
    TextView vipMoneyAmount;//加急邮费
    @BindView(R.id.why)
    TextView why;
    @BindView(R.id.vip)
    CheckBox vip;
    @BindView(R.id.vipLinearLayout)
    LinearLayout vipLinearLayout;
    @BindView(R.id.couponRelative)
    RelativeLayout couponRelative;
    @BindView(R.id.select_urgent)
    RelativeLayout select_urgent;
    @BindView(R.id.vipMoney)
    TextView vipMoney;//加急邮费价钱
    @BindView(R.id.toTime)
    TextView toTime;//送达时间
    private SettleAccountsEntity settleAccountsEntity;
    private List<SettleGoods> settleGoodsList = new ArrayList<>();
    private List<SettleShopGoodsCar> settleShopGoodsCars;
    private StringBuilder carIds = new StringBuilder();
    private Accept accept;

    public static final int REQ_CODE = 0x01;

    private Integer couponId;//要提交的优惠券ID
    private String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    private String[] times = {"8:00-10:00", "10:00-12:00", "12:00-14:00", "14:00-16:00", "16:00-18:00", "18:00-20:00"};
    private ListView urgent_day;
    private ListView urgent_hour;
    List<String> dayList = new ArrayList<>();
    List<String> timeList = new ArrayList<>();
    List<String> latertimeList = new ArrayList<>();
    private String seleDay, seleTime, tomorrow, acquired, afterTomorrow;
    private String refId;
    private String curTime;
    private String defautId;
    Dialog tdialog;
    private String seHour, seDay, postageMoney, ispost;
    private int curIndex;
    private byte[] sex = new byte[6];
    private byte[] name = new byte[32];
    private byte[] birth = new byte[18];
    private byte[] nation = new byte[12];
    private byte[] address = new byte[72];
    private byte[] Department = new byte[32];
    private byte[] IDNo = new byte[38];
    private byte[] EffectDate = new byte[18];
    private byte[] ExpireDate = new byte[18];
    byte[] BmpFile = new byte[38556];
    private publicSecurityIDCardLib iDCardDevice;
    private Handler mHandler;
    boolean isstop = false;
    private String pkName;
    EditText nameEdit;
    EditText idCardEdit;
    Dialog dialog;

    private String getActivityTag() {
        return OrderSureActivity.class.getSimpleName();
    }

    @Override
    public void initView() {
        pkName = this.getPackageName();
        title.setText(BaseApplication.getIntstance().getResources().getString(R.string.sure_order));
        action.setVisibility(View.GONE);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(this);
        mCommitOrder.setOnClickListener(this);
        mAccpetNone.setOnClickListener(this);
        mAcceptLinearlayout.setOnClickListener(this);
        couponRelative.setOnClickListener(this);
        select_urgent.setOnClickListener(this);
        refId = SPUtils.getStringData(OrderSureActivity.this, SPUtils.REFID);
        vipTextView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        why.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        vip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    vipLinearLayout.setVisibility(View.VISIBLE);
                } else {
                    vipLinearLayout.setVisibility(View.GONE);
                    toTime.setText("送达时间:");
                    vipMoney.setText("加急邮费:");
                    mTotalMoney.setText((NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount())));
                }
            }
        });
        if(TDevice.isTablet(getApplicationContext())){
            HandlerThread handlerThread = new HandlerThread("MyHandlerThread");
            handlerThread.start();
            mHandler = new Handler(handlerThread.getLooper(), new Handler.Callback() {
                @Override
                public boolean handleMessage(Message message) {
                    switch (message.what) {
                        case 1001:
                            if (!isstop) {
                                mHandler.post(getdata);
                            }
                            break;
                        case 1002:
                            mHandler.removeCallbacks(getdata);
                            break;
                    }
                    return false;
                }
            });
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == back.getId()) {
            ActivityManager.getInstance().finishActivity();
        } else if (v.getId() == mCommitOrder.getId()) {
            commitOrder();
        } else if (v.getId() == mAccpetNone.getId()) {
            Intent intent = new Intent(OrderSureActivity.this, AddAddressActivity.class);
            intent.putExtra("flag", "orderSure");
            startActivityForResult(intent, REQ_CODE);
        } else if (v.getId() == couponRelative.getId()) {
            if (settleAccountsEntity.getCoupons().size() <= 1) {
                BaseApplication.showToast(R.string.no_coupon);
            } else {
                final Dialog dialog = new Dialog(OrderSureActivity.this, R.style.Transparent);
                dialog.setContentView(R.layout.coupon_bottom_dialog);
                TextView close = (TextView) dialog.findViewById(R.id.close);
                close.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.setCanceledOnTouchOutside(true);

                final ListView listView = (ListView) dialog.findViewById(R.id.listview);
                listView.setAdapter(new BaseAdapter() {
                    @Override
                    public int getCount() {
                        return settleAccountsEntity.getCoupons().size();
                    }

                    @Override
                    public Object getItem(int position) {
                        return settleAccountsEntity.getCoupons().get(position);
                    }

                    @Override
                    public long getItemId(int position) {
                        return position;
                    }

                    @Override
                    public View getView(final int position, View convertView, ViewGroup parent) {
                        convertView = LayoutInflater.from(OrderSureActivity.this).inflate(R.layout.coupon_item, null);
                        TextView couponName = (TextView) convertView.findViewById(R.id.couponName);
                        CheckBox couponImg = (CheckBox) convertView.findViewById(R.id.couponImg);
                        couponName.setText(settleAccountsEntity.getCoupons().get(position).getName());
                        couponImg.setChecked(settleAccountsEntity.getCoupons().get(position).isCheck());
                        couponImg.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                couponId = settleAccountsEntity.getCoupons().get(position).getId();

                                for (int i = 0; i < settleAccountsEntity.getCoupons().size(); i++) {
                                    settleAccountsEntity.getCoupons().get(i).setCheck(false);
                                }
                                settleAccountsEntity.getCoupons().get(position).setCheck(true);
                                ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
                            }
                        });
                        return convertView;
                    }
                });

                Window win = dialog.getWindow();
                win.setGravity(Gravity.BOTTOM);
                win.getDecorView().setPadding(0, 0, 0, 0);
                WindowManager.LayoutParams lp = win.getAttributes();
                lp.width = WindowManager.LayoutParams.FILL_PARENT;
                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                lp.dimAmount = 0.5f;
                win.setAttributes(lp);
                dialog.show();
            }

        } else if (v.getId() == mAcceptLinearlayout.getId()) {
            Intent intent = new Intent(getApplicationContext(), AddressActivity.class);
            intent.putExtra("flag", "orderSure");
            startActivityForResult(intent, REQ_CODE);
        } else if (v.getId() == select_urgent.getId()) {
            toshowTime();
        }
    }

    //显示送达时间
    private void toshowTime() {
        tdialog = new Dialog(OrderSureActivity.this, R.style.Transparent);
        tdialog.setContentView(R.layout.urgent_time);
        urgent_day = (ListView) tdialog.findViewById(R.id.urgent_day);
        urgent_hour = (ListView) tdialog.findViewById(R.id.urgent_hour);
        showWeek();

        tdialog.setCanceledOnTouchOutside(true);
        Window win = tdialog.getWindow();
        win.setGravity(Gravity.BOTTOM);
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        lp.dimAmount = 0.5f;
        win.setAttributes(lp);
        tdialog.show();
    }

    private void showWeek() {
        dayList.clear();
        timeList.clear();
        latertimeList.clear();
        long time = System.currentTimeMillis();
        Date date = new Date(time);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 EEEE");
        format = new SimpleDateFormat("EEEE");
        String curWeek = format.format(date);
        format = new SimpleDateFormat("HH");
        curTime = format.format(date);
        format = new SimpleDateFormat("yyyy-MM-dd");


        seleDay = format.format(date);

        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, +1);
        format.format(c.getTime());

        Calendar d = Calendar.getInstance();
        d.add(Calendar.DAY_OF_MONTH, +2);
        format.format(d.getTime());

        Calendar e = Calendar.getInstance();
        e.add(Calendar.DAY_OF_MONTH, +3);
        format.format(d.getTime());

        tomorrow = format.format(c.getTime()); //明天
        acquired = format.format(d.getTime());  //后天
        afterTomorrow = format.format(e.getTime());  //大后天
//        Log.i("aaa","---"+seleDay+"--1-"+tomorrow+"--2--"+acquired+"-afterTomorrow-"+afterTomorrow);
//        if(curWeek.equals("星期日")){
//            dayList.add("今天("+weeks[0]+")");
//            dayList.add("明天("+weeks[1]+")");
//            dayList.add("后天("+weeks[2]+")");
//        }else if(curWeek.equals("星期一")){
//            dayList.add("今天("+weeks[1]+")");
//            dayList.add("明天("+weeks[2]+")");
//            dayList.add("后天("+weeks[3]+")");
//        }else if(curWeek.equals("星期二")){
//            dayList.add("今天("+weeks[2]+")");
//            dayList.add("明天("+weeks[3]+")");
//            dayList.add("后天("+weeks[4]+")");
//        }else if(curWeek.equals("星期三")){
//            dayList.add("今天("+weeks[3]+")");
//            dayList.add("明天("+weeks[4]+")");
//            dayList.add("后天("+weeks[5]+")");
//        }else if(curWeek.equals("星期四")){
//            dayList.add("今天("+weeks[4]+")");
//            dayList.add("明天("+weeks[5]+")");
//            dayList.add("后天("+weeks[6]+")");
//        }else if(curWeek.equals("星期五")){
//            dayList.add("今天("+weeks[5]+")");
//            dayList.add("明天("+weeks[6]+")");
//            dayList.add("后天("+weeks[0]+")");
//        }else if(curWeek.equals("星期六")){
//            dayList.add("今天("+weeks[6]+")");
//            dayList.add("明天("+weeks[0]+")");
//            dayList.add("后天("+weeks[1]+")");
//        }
        if (Integer.parseInt(curTime) >= 16) {
            if (curWeek.equals("星期日")) {
                dayList.add("明天(" + weeks[1] + ")");
                dayList.add("后天(" + weeks[2] + ")");
                dayList.add("大后天(" + weeks[3] + ")");
            } else if (curWeek.equals("星期一")) {
                dayList.add("明天(" + weeks[2] + ")");
                dayList.add("后天(" + weeks[3] + ")");
                dayList.add("大后天(" + weeks[4] + ")");
            } else if (curWeek.equals("星期二")) {
                dayList.add("明天(" + weeks[3] + ")");
                dayList.add("后天(" + weeks[4] + ")");
                dayList.add("大后天(" + weeks[5] + ")");
            } else if (curWeek.equals("星期三")) {
                dayList.add("明天(" + weeks[4] + ")");
                dayList.add("后天(" + weeks[5] + ")");
                dayList.add("大后天(" + weeks[6] + ")");
            } else if (curWeek.equals("星期四")) {
                dayList.add("明天(" + weeks[5] + ")");
                dayList.add("后天(" + weeks[6] + ")");
                dayList.add("大后天(" + weeks[0] + ")");
            } else if (curWeek.equals("星期五")) {
                dayList.add("明天(" + weeks[6] + ")");
                dayList.add("后天(" + weeks[0] + ")");
                dayList.add("大后天(" + weeks[1] + ")");
            } else if (curWeek.equals("星期六")) {
                dayList.add("明天(" + weeks[0] + ")");
                dayList.add("后天(" + weeks[1] + ")");
                dayList.add("大后天(" + weeks[2] + ")");
            }
        } else {
            if (curWeek.equals("星期日")) {
                dayList.add("今天(" + weeks[0] + ")");
                dayList.add("明天(" + weeks[1] + ")");
                dayList.add("后天(" + weeks[2] + ")");
            } else if (curWeek.equals("星期一")) {
                dayList.add("今天(" + weeks[1] + ")");
                dayList.add("明天(" + weeks[2] + ")");
                dayList.add("后天(" + weeks[3] + ")");
            } else if (curWeek.equals("星期二")) {
                dayList.add("今天(" + weeks[2] + ")");
                dayList.add("明天(" + weeks[3] + ")");
                dayList.add("后天(" + weeks[4] + ")");
            } else if (curWeek.equals("星期三")) {
                dayList.add("今天(" + weeks[3] + ")");
                dayList.add("明天(" + weeks[4] + ")");
                dayList.add("后天(" + weeks[5] + ")");
            } else if (curWeek.equals("星期四")) {
                dayList.add("今天(" + weeks[4] + ")");
                dayList.add("明天(" + weeks[5] + ")");
                dayList.add("后天(" + weeks[6] + ")");
            } else if (curWeek.equals("星期五")) {
                dayList.add("今天(" + weeks[5] + ")");
                dayList.add("明天(" + weeks[6] + ")");
                dayList.add("后天(" + weeks[0] + ")");
            } else if (curWeek.equals("星期六")) {
                dayList.add("今天(" + weeks[6] + ")");
                dayList.add("明天(" + weeks[0] + ")");
                dayList.add("后天(" + weeks[1] + ")");
            }
        }
        if (Integer.parseInt(curTime) <= 6 && Integer.parseInt(curTime) >= 0) {
            timeList.add(times[0]);
            timeList.add(times[1]);
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("07") || curTime.equals("08")) {
            timeList.add(times[1]);
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("09") || curTime.equals("10")) {
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("11") || curTime.equals("12")) {
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("13") || curTime.equals("14")) {
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("15") || curTime.equals("16")) {
            timeList.add(times[5]);
        }
//        try {
//
//
//        if(Integer.parseInt(curTime)>=16){
//            if(curWeek.equals("星期日")){
//                dayList.add("明天("+weeks[1]+")");
//                dayList.add("后天("+weeks[2]+")");
//                dayList.add("大后天("+weeks[3]+")");
//            }else if(curWeek.equals("星期一")){
//                dayList.add("明天("+weeks[2]+")");
//                dayList.add("后天("+weeks[3]+")");
//                dayList.add("大后天("+weeks[4]+")");
//            }else if(curWeek.equals("星期二")){
//                dayList.add("明天("+weeks[3]+")");
//                dayList.add("后天("+weeks[4]+")");
//                dayList.add("大后天("+weeks[5]+")");
//            }else if(curWeek.equals("星期三")){
//                dayList.add("明天("+weeks[4]+")");
//                dayList.add("后天("+weeks[5]+")");
//                dayList.add("大后天("+weeks[6]+")");
//            }else if(curWeek.equals("星期四")){
//                dayList.add("明天("+weeks[5]+")");
//                dayList.add("后天("+weeks[6]+")");
//                dayList.add("大后天("+weeks[0]+")");
//            }else if(curWeek.equals("星期五")){
//                dayList.add("明天("+weeks[6]+")");
//                dayList.add("后天("+weeks[0]+")");
//                dayList.add("大后天("+weeks[1]+")");
//            }else if(curWeek.equals("星期六")){
//                dayList.add("明天("+weeks[0]+")");
//                dayList.add("后天("+weeks[1]+")");
//                dayList.add("大后天("+weeks[2]+")");
//            }
//        }else{
//            if(curWeek.equals("星期日")){
//                dayList.add("今天("+weeks[0]+")");
//                dayList.add("明天("+weeks[1]+")");
//                dayList.add("后天("+weeks[2]+")");
//            }else if(curWeek.equals("星期一")){
//                dayList.add("今天("+weeks[1]+")");
//                dayList.add("明天("+weeks[2]+")");
//                dayList.add("后天("+weeks[3]+")");
//            }else if(curWeek.equals("星期二")){
//                dayList.add("今天("+weeks[2]+")");
//                dayList.add("明天("+weeks[3]+")");
//                dayList.add("后天("+weeks[4]+")");
//            }else if(curWeek.equals("星期三")){
//                dayList.add("今天("+weeks[3]+")");
//                dayList.add("明天("+weeks[4]+")");
//                dayList.add("后天("+weeks[5]+")");
//            }else if(curWeek.equals("星期四")){
//                dayList.add("今天("+weeks[4]+")");
//                dayList.add("明天("+weeks[5]+")");
//                dayList.add("后天("+weeks[6]+")");
//            }else if(curWeek.equals("星期五")){
//                dayList.add("今天("+weeks[5]+")");
//                dayList.add("明天("+weeks[6]+")");
//                dayList.add("后天("+weeks[0]+")");
//            }else if(curWeek.equals("星期六")){
//                dayList.add("今天("+weeks[6]+")");
//                dayList.add("明天("+weeks[0]+")");
//                dayList.add("后天("+weeks[1]+")");
//            }
//        }
        UrgentDayAdpter dayAdapter = new UrgentDayAdpter(OrderSureActivity.this, dayList);
        urgent_day.setAdapter(dayAdapter);
        latertimeList.add(times[0]);
        latertimeList.add(times[1]);
        latertimeList.add(times[2]);
        latertimeList.add(times[3]);
        latertimeList.add(times[4]);
        latertimeList.add(times[5]);
        if (Integer.parseInt(curTime) >= 16) {
            UrgentTimeAdpter newadapter = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
            urgent_hour.setAdapter(newadapter);
            urgent_hour.setOnItemClickListener(Onelistener);
        } else {
            UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(OrderSureActivity.this, timeList);
            urgent_hour.setAdapter(timeAdapter);
            urgent_hour.setOnItemClickListener(Onelistener);
        }
        urgent_day.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (Integer.parseInt(curTime) >= 16) {
                    if (i == 0) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Onelistener);
                    } else if (i == 1) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Twolistener);
                    } else if (i == 2) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Threelistener);
                    }
                } else {
                    if (i == 0) {
                        UrgentTimeAdpter tone = new UrgentTimeAdpter(OrderSureActivity.this, timeList);
                        urgent_hour.setAdapter(tone);
                        urgent_hour.setOnItemClickListener(Onelistener);
                    } else if (i == 1) {
                        UrgentTimeAdpter ttwo = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
                        urgent_hour.setAdapter(ttwo);
                        urgent_hour.setOnItemClickListener(Twolistener);
                    } else if (i == 2) {
                        UrgentTimeAdpter tthree = new UrgentTimeAdpter(OrderSureActivity.this, latertimeList);
                        urgent_hour.setAdapter(tthree);
                        urgent_hour.setOnItemClickListener(Threelistener);
                    }
                }


            }
        });

//        UrgentTimeAdpter timeAdapter=new UrgentTimeAdpter(OrderSureActivity.this,timeList);
//        urgent_hour.setAdapter(timeAdapter);
//        urgent_hour.setOnItemClickListener(Onelistener);
//
//        urgent_day.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Log.i("aaa","--ii--"+i);
//
//                if(i==0){
//                    UrgentTimeAdpter timeAdapter=new UrgentTimeAdpter(OrderSureActivity.this,timeList);
//                    urgent_hour.setAdapter(timeAdapter);
//                    urgent_hour.setOnItemClickListener(Onelistener);
//                }else if(i==1){
//                    UrgentTimeAdpter timeAdapter=new UrgentTimeAdpter(OrderSureActivity.this,latertimeList);
//                    urgent_hour.setAdapter(timeAdapter);
//                    urgent_hour.setOnItemClickListener(Twolistener);
//                }else if(i==2){
//                    UrgentTimeAdpter timeAdapter=new UrgentTimeAdpter(OrderSureActivity.this,latertimeList);
//                    urgent_hour.setAdapter(timeAdapter);
//                    urgent_hour.setOnItemClickListener(Threelistener);
//                }
//            }
//        });
//        }catch (Exception ee){
//            ee.printStackTrace();
//        }
    }

    //选择今天
    public AdapterView.OnItemClickListener Onelistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (Integer.parseInt(curTime) >= 16) { //选择明天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(0) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(2, seHour);//计算邮费
            } else { //选择今天
                toTime.setText("送达时间:" + dayList.get(0) + " " + timeList.get(i));
                String t[] = timeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(1, seHour);//计算邮费
            }
//            toTime.setText("送达时间:"+dayList.get(0)+" "+timeList.get(i));
//                String t[]=timeList.get(i).split(":00-");
//                seHour=t[0];
//                toaddPostage(1,seHour);//计算邮费
        }

    };

    //选择明天
    public AdapterView.OnItemClickListener Twolistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (Integer.parseInt(curTime) >= 16) {//选择明天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(1) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(3, seHour);//计算邮费
            } else {//选择明天
                toTime.setText("送达时间:" + dayList.get(1) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(2, seHour);//计算邮费
            }

//            if(Integer.parseInt(curTime)>=16){//选择明天(当前是明天)
//                toTime.setText("送达时间:"+dayList.get(1)+" "+latertimeList.get(i));
//                String t[]=latertimeList.get(i).split(":00-");
//                seHour=t[0];
//                toaddPostage(3,seHour);//计算邮费
//            }else{//选择明天
//                toTime.setText("送达时间:"+dayList.get(1)+" "+latertimeList.get(i));
//                String t[]=latertimeList.get(i).split(":00-");
//                seHour=t[0];
//                toaddPostage(2,seHour);//计算邮费
//            }
        }
    };

    public AdapterView.OnItemClickListener Threelistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            if (Integer.parseInt(curTime) >= 16) { //选择大后天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(2) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(4, seHour);//计算邮费
            } else {                              //选择后天
                toTime.setText("送达时间:" + dayList.get(2) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(3, seHour);//计算邮费
            }
        }
    };

    private void toaddPostage(final int index, final String hour) {
        OkUtilCallback callback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                Gson gson = new Gson();
                Entity result = gson.fromJson(response, Entity.class);
                if (result.getResult().equals("OK")) {
                    tdialog.dismiss();
                    postageMoney = (NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount() + result.getUrgentAmount()));
                    vipMoney.setText("加急邮费: ￥" + NetUtils.setDecimal(result.getUrgentAmount()) + "元");
                    mTotalMoney.setText(postageMoney);
                    ispost = NetUtils.setDecimal(result.getUrgentAmount());
                } else {
                    TipsToast.makeText(OrderSureActivity.this, result.getResult(), TipsToast.LENGTH_SHORT).show();
                    postageMoney = (NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount()));
                    vipMoney.setText("加急邮费: ￥" + "0.0元");
                    ispost = "";
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                postageMoney = (NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount()));
                ispost = "";
                vipMoney.setText("加急邮费: ￥" + "0.0元");
                TipsToast.makeText(OrderSureActivity.this, "系统异常,请稍候再试", TipsToast.LENGTH_SHORT).show();
            }
        };
        String params;
        if (index == 1) {
            params = "areaIds=" + refId + "&date=" + seleDay + "&hour=" + hour;
            seDay = seleDay;
        } else if (index == 2) {
            params = "areaIds=" + refId + "&date=" + tomorrow + "&hour=" + hour;
            seDay = tomorrow;
        } else if (index == 4) {
            params = "areaIds=" + refId + "&date=" + afterTomorrow + "&hour=" + hour;
            seDay = afterTomorrow;
        } else {
            params = "areaIds=" + refId + "&date=" + acquired + "&hour=" + hour;
            seDay = acquired;
        }
        OKUtilAPI.post(OKUtilAPI.countStamp, params, callback);
    }

    /**
     * 添加完收货地址后
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQ_CODE) {
                mAccpetNone.setVisibility(View.GONE);
                mAcceptLinearlayout.setVisibility(View.VISIBLE);
                accepterTextView.setText(data.getStringExtra("name"));
//                     Log.e("BBBB","NAME ===== "+data.getStringExtra("name"));
                telTextView.setText(data.getStringExtra("phone"));
                addressTextView.setText(data.getStringExtra("address"));
                vip.setChecked(false);
                refId = data.getStringExtra("refId");
                toTime.setText("送达时间:");
                vipMoney.setText("加急邮费:");
                postageMoney = (NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount()));
                mTotalMoney.setText(postageMoney);
            }
        }
    }

    /**
     * 提交订单请求
     */
    private void commitOrder() {

        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                TLog.log(getActivityTag(), response);
                UserData entity = gson.fromJson(response, UserData.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    String autoStr = entity.getAuth();
                    if (AppConfig.unAuth.equalsIgnoreCase(autoStr) || AppConfig.authFail.equalsIgnoreCase(autoStr)) {
                        if(TDevice.isTablet(getApplicationContext())){
                            iDCardDevice = new publicSecurityIDCardLib(mContext);
                            iDCardDevice = null;
                            isstop = false;
                            mHandler.sendEmptyMessage(1001);
                            dialog = new Dialog(mContext, R.style.dialog_common);
                            View bv = dialog.findViewById(android.R.id.title);
                            bv.setVisibility(View.GONE);
                            dialog.setContentView(R.layout.dialog_idcard);
                            dialog.setCanceledOnTouchOutside(true);
                            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                                @Override
                                public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                                        mHandler.sendEmptyMessage(1002);
                                        isstop = true;
                                        dialog.dismiss();
                                    }
                                    return false;
                                }
                            });
//                            setTr(dialog);
                            dialog.show();
                        }else {
                            dialog = new Dialog(OrderSureActivity.this, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                            View bv = dialog.findViewById(android.R.id.title);
                            bv.setVisibility(View.GONE);
                            dialog.setContentView(R.layout.authentication);
                            dialog.setCanceledOnTouchOutside(true);
                            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                                @Override
                                public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                                        dialog.dismiss();
                                    }
                                    return false;
                                }
                            });
                            TextView whyTextView = (TextView) dialog.findViewById(R.id.whyTextView);
                            whyTextView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线


                            nameEdit = (EditText) dialog.findViewById(R.id.nameEdit);
                            idCardEdit = (EditText) dialog.findViewById(R.id.idCardEdit);
                            TextView cancelTV = (TextView) dialog.findViewById(R.id.cancelTV);
                            TextView commit = (TextView) dialog.findViewById(R.id.commit);
                            cancelTV.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    if (TDevice.isTablet(getApplicationContext())) {
                                        mHandler.sendEmptyMessage(1002);
                                        isstop = true;
                                    }
                                    dialog.dismiss();
                                }
                            });

                            commit.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                        if (StringUtils.isEmpty(nameEdit.getText().toString())) {
                                            BaseApplication.showToast(R.string.names_none);
                                            return;
                                        }
                                        if (StringUtils.isEmpty(idCardEdit.getText().toString())) {
                                            BaseApplication.showToast(R.string.id_card_none);
                                            return;
                                        }
                                        commitAuthRequest(nameEdit.getText().toString(), idCardEdit.getText().toString(), dialog);
                                }
                            });
                            dialog.show();
                            final Dialog callDialog = new Dialog(OrderSureActivity.this, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                            View bv1 = callDialog.findViewById(android.R.id.title);
                            bv1.setVisibility(View.GONE);
//                        callDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                            callDialog.setContentView(R.layout.wht_auth);
//                        TextView callTV = (TextView) callDialog.findViewById(R.id.call);
//                        callTV.setOnClickListener(new View.OnClickListener() {
//                            public void onClick(View v) {
//
//                            }
//                        });
                            ImageView deleteCall = (ImageView) callDialog.findViewById(R.id.delete_icon);
                            deleteCall.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    callDialog.dismiss();
                                }
                            });

                            callDialog.setCanceledOnTouchOutside(true);
                            whyTextView.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    callDialog.show();
                                }
                            });

                        }
                    } else {
                        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
                            @Override
                            public void onMyResponse(String response, int id) {
                                hideWaitDialog();
                                TLog.log(getActivityTag(), response);
                                Entity entity = gson.fromJson(response, Entity.class);
                                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                                    AppConfig.isRefreshShocpar = true;
                                    Intent intent = new Intent(OrderSureActivity.this, PayActivity.class);
                                    intent.putExtra("orderNo", entity.getOrderNo());
                                    if (settleGoodsList.size() > 0) {
                                        intent.putExtra("goodsName", settleGoodsList.get(0).getGoodsName());
                                    }
                                    Log.i("aaa", "---page--" + postageMoney);
                                    if (TextUtils.isEmpty(ispost)) {
                                        intent.putExtra("goodsCurPrice", Double.valueOf(NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount())));
                                    } else if (!TextUtils.isEmpty(ispost)) {
                                        intent.putExtra("goodsCurPrice", Double.valueOf(postageMoney));
                                    }
                                    startActivity(intent);
                                    finish();
                                }
                            }
                        };

                        if (carIds.toString().length() == 0) {
                            BaseApplication.getIntstance().showToast(R.string.goods_none);
                            return;
                        }

                        if (settleShopGoodsCars.size() == 0) {
                            return;
                        }

                        showWaitDialog(BaseApplication.getIntstance().getString(R.string.order_adding));
                        String userId = SPUtils.getStringData(OrderSureActivity.this, SPUtils.USERID);
                        String ids = carIds.substring(0, carIds.toString().length() - 1);
                        String remarks = mBuyerTips.getText().toString();
                        String mySign = userId + ids + AppConfig.SECRETKEY;
                        mySign = MD5.GetMD5Code(mySign);
                        String url = "";
                        if (vip.isChecked() == false) {
                            url = "userId=" + userId + "&ids=" + ids + "&remarks=" + remarks + "&sign=" + mySign + "&addrId=" + AppConfig.CITY_ID;
                        } else if (vip.isChecked() == true) {
                            url = "userId=" + userId + "&ids=" + ids + "&remarks=" + remarks + "&sign=" + mySign + "&date=" + seDay + "&hour=" + seHour + "&addrId=" + AppConfig.CITY_ID;
                        }
//                        String url = "userId=" + userId+"&ids="+ids+"&remarks="+remarks+"&sign="+mySign+"&addrId="+AppConfig.CITY_ID;
                        if (couponId != null && couponId > 0) {
                            url += "&couponId=" + couponId;
                        }

                        if(TDevice.isTablet(OrderSureActivity.this)){
                            url = url + "&deviceType=ATM";
                        }

                        OKUtilAPI.post(OKUtilAPI.addOrders, url, okUtilCallback);
                    }
                }
            }
        };
        String userId = SPUtils.getStringData(this, SPUtils.USERID);
        OKUtilAPI.post(OKUtilAPI.getUser, "userId=" + userId, okUtilCallback);
    }

    Runnable getdata = new Runnable() {
        @Override
        public void run() {
            getIdCardData();
        }
    };

    private void getIdCardData() {
        int ret;
        if (iDCardDevice == null) {
            iDCardDevice = new publicSecurityIDCardLib(mContext);
        }
        ret = iDCardDevice.readBaseMsgToStr(pkName, BmpFile, name, sex, nation, birth, address, IDNo, Department,
                EffectDate, ExpireDate);
        /********************************将图片放到textview里边显示****************************/
//		int[] colors =iDCardDevice.convertByteToColor(BmpFile);
//		b = Bitmap.createBitmap(colors, 102, 126, Bitmap.Config.ARGB_8888);
//		ImageSpan imgSpan = new ImageSpan(b);
//		SpannableString spanString = new SpannableString("icon");
//		spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        /**************************************************************************************/
        System.out.println("ret == "+ret);
        if (ret == 0x90) {
            mHandler.sendEmptyMessage(1002);
                int[] colors = iDCardDevice.convertByteToColor(BmpFile);
//                b = Bitmap.createBitmap(colors, 102, 126, Bitmap.Config.ARGB_8888);
//                names = new String(name, "Unicode");
//                sexs = new String(sex, "Unicode");
//                nations = new String(nation, "Unicode");
//                births = new String(birth, "Unicode");
//                addr = new String(address, "Unicode");
//                IDNos = new String(IDNo, "Unicode");
//                departments = new String(Department, "Unicode");
//                effectDates = new String(EffectDate, "Unicode");
//                departments = departments.replace(" ", "");
//                names = names.replace(" ", "");
//                sexs = sexs.replaceAll("[^\\u4e00-\\u9fa5]", "");
//                nations = nations.replaceAll("[^\\u4e00-\\u9fa5]", "");
//                addr = addr.replace(" ", "");
//                expireDates = new String(ExpireDate, "Unicode");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (dialog.isShowing()) {
                            dialog.dismiss();
                        }
                        final Dialog dialog1 = new Dialog(mContext, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        View bv = dialog1.findViewById(android.R.id.title);
                        bv.setVisibility(View.GONE);
                        dialog1.setContentView(R.layout.dialog_idcard_show);
                        dialog1.setCanceledOnTouchOutside(true);
                        dialog1.setOnKeyListener(new DialogInterface.OnKeyListener() {
                            @Override
                            public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                                    dialog1.dismiss();
                                }
                                return false;
                            }
                        });
//                        setTr(dialog1);
                        final TextView textView1 = (TextView) dialog1.findViewById(R.id.tv_name);
                        TextView textView2 = (TextView) dialog1.findViewById(R.id.tv_sex);
                        TextView textView3 = (TextView) dialog1.findViewById(R.id.tv_bir);
                        final TextView textView4 = (TextView) dialog1.findViewById(R.id.tv_idcard);
                        TextView textView5 = (TextView) dialog1.findViewById(R.id.tv_que);
                        textView5.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                commitAuthRequest(textView1.getText().toString().trim(), textView4.getText().toString().trim(), dialog1);
                            }
                        });
                        textView1.setText("姓名：" + new String(name, "Unicode"));
                        textView2.setText("性别：" + new String(sex, "Unicode"));
                        textView3.setText("出生日期：" + new String(birth, "Unicode"));
                        textView4.setText("身份证号：" + new String(IDNo, "Unicode"));
                        dialog1.show();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            });
//				show = "姓名:"+new String(name, "Unicode")+'\n'
//						+"性别:"+new String(sex, "Unicode")+'\n'
//						+"民族:"+ new String(nation, "Unicode")+"族"+'\n'
//						+"出生日期:"+new String(birth, "Unicode")+'\n'
//						+"住址:"+new String(address, "Unicode")+'\n'
//						+"身份证号码:"+new String(IDNo, "Unicode")+'\n'
//						+"签发机关:"+new String(Department, "Unicode")+'\n'
//						+"有效日期:"+ new String(EffectDate, "Unicode") + "至" + new String(ExpireDate, "Unicode")+'\n';
        } else {
            mHandler.sendEmptyMessage(1001);
//			ToastUtil.ShowToast(mContext,"请将身份证放在识读区",200);
//			show ="读基本信息失败:"+String.format("0x%02x", ret);
        }
//		if(ret==0x90) viewBmp.setText(spanString);  			/*显示头像*/
    }

    /**
     * 提交认证请求
     *
     * @param name
     * @param idcard
     * @param dialog
     */
    private void commitAuthRequest(String name, String idcard, final Dialog dialog) {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                hideWaitDialog();
                TLog.log(getActivityTag(), response);
                Entity entity = gson.fromJson(response, Entity.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                    if (TDevice.isTablet(getApplicationContext())) {
                        mHandler.sendEmptyMessage(1001);
                    }
                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    if (TDevice.isTablet(getApplicationContext())) {
                        mHandler.sendEmptyMessage(1001);
                    }
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.showToast(R.string.auth_commit_success);
                    if (dialog != null) dialog.dismiss();
                }
            }
        };
        showWaitDialog(BaseApplication.getIntstance().getString(R.string.auth_commiting));
        String userId = SPUtils.getStringData(OrderSureActivity.this, SPUtils.USERID);
        int ifATM = 0;
        if (TDevice.isTablet(getApplicationContext())) {
            ifATM = 1;//是ATM验证
        } else {
            ifATM = 0;
        }
        OKUtilAPI.post(OKUtilAPI.saveNameAuth, "userId=" + userId + "&name=" + name + "&idcard=" + idcard + "&ifATM=" + ifATM, okUtilCallback);
    }

    @Override
    public void initData() {
        settleAccountsEntity = gson.fromJson(getIntent().getStringExtra("response"), SettleAccountsEntity.class);
        accept = settleAccountsEntity.getAccept();
        settleShopGoodsCars = settleAccountsEntity.getShopcar().getList();//获取所有的商家

        Coupon coupon = new Coupon();
        coupon.setId(0);
        coupon.setName(BaseApplication.resources().getString(R.string.no_use_coupon));

        List<Coupon> coupons = settleAccountsEntity.getCoupons();
        coupons.add(coupon);


        mTotalMoney.setText(settleAccountsEntity.getShopcar().getAmount() + "");

        if (accept == null) {
            mAccpetNone.setVisibility(View.VISIBLE);
            mAcceptLinearlayout.setVisibility(View.GONE);
        } else {
            mAccpetNone.setVisibility(View.GONE);
            mAcceptLinearlayout.setVisibility(View.VISIBLE);
            accepterTextView.setText(accept.getName());
            telTextView.setText(accept.getPhone());
            addressTextView.setText(accept.getDetailAddress());//////////////////////////
        }

        for (SettleShopGoodsCar shopGoodsCar : settleShopGoodsCars) {
            List<SettleGoods> goodcars = shopGoodsCar.getGoodsList();
            settleGoodsList.addAll(goodcars);
        }

        for (SettleGoods goods : settleGoodsList) {
            carIds.append(goods.getId() + ",");
        }

        listview.setAdapter(adapter);

    }

    @Override
    public int getContentViewId() {
        return R.layout.order_sure_activity;
    }

    @Override
    protected String getFragmentTag() {
        return OrderSureActivity.class.getSimpleName();
    }

    final BaseAdapter adapter = new BaseAdapter() {

        @Override
        public int getCount() {
            return settleGoodsList.size();
        }

        @Override
        public Object getItem(int position) {
            return settleGoodsList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(OrderSureActivity.this).inflate(R.layout.order_sure_item, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            SettleGoods goods = settleGoodsList.get(position);


            String[] nUrl = goods.getGoodsImg().split("\\.");
            StringBuffer buffer = new StringBuffer();
            buffer.append(nUrl[0]).append("_360.").append(nUrl[1]);
            Glide.with(OrderSureActivity.this).load(OKUtilAPI.imgBaseUrl + buffer).into(holder.gLogo);
            holder.gName.setText(goods.getGoodsName());
            holder.gPrice.setText(AppConfig.MONEY_SYMBEL + goods.getPrice());
            holder.gNum.setText("X" + goods.getNum() + "");
            holder.attrs.setText(goods.getAttrs());

            return convertView;
        }

        class ViewHolder {
            ImageView gLogo;
            TextView gName;
            TextView gPrice;
            TextView gNum;
            TextView attrs;

            public ViewHolder(View view) {
                AutoUtils.autoSize(view);
                gLogo = (ImageView) view.findViewById(R.id.gLogo);
                gName = (TextView) view.findViewById(R.id.gName);
                gPrice = (TextView) view.findViewById(R.id.gPrice);
                gNum = (TextView) view.findViewById(R.id.gNum);
                attrs = (TextView) view.findViewById(R.id.attrs);
            }
        }
    };

    @Override
    protected void onStop() {
        super.onStop();
        isstop = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        isstop = false;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        if(TDevice.isTablet(getApplicationContext())){
            mHandler.removeCallbacks(getdata);
            mHandler.removeCallbacksAndMessages(null);
        }
    }
}
